<html>
<head>
    <title>Consulta</title>
    <link rel="stylesheet" type="text/css" media="screen" href="theme/default/style.css" />
</head>

<body>

<?php

$table = "filtering.productivity_map_after";
$the_geom = "thepoint_lonlat";
$lon = $_GET["lon"];
$lat = $_GET["lat"];

//$lon = substr($lon,0,strpos($lon,'.'));
//$lat = substr($lat,0,strpos($lat,'.'));

$sql = "select
          st_geometrytype($the_geom) as geometrytype,
          st_area($the_geom) as area, *
        from $table
        where
          st_contains($the_geom,st_setsrid(st_makepoint($lon, $lat),4326))";

$db = pg_connect("dbname=postgis user=postgres password=tcc09")
or die("Could not connect");
$result = pg_query($db, $sql);
//$arr = pg_fetch_all($result);
while( $row = pg_fetch_assoc($result) )
{
  print "<table>";
  foreach ( array_keys($row) as $column_name )
  {
    if ( $column_name <> "the_geom" )
    {
      print "<tr>";
      print "<td>" . $column_name . "</td>";
      print "<td>" . $row[$column_name] . "</td>";
      print "</tr>";
    }
  }
  print "</table>";
}
print "<table><tr><td><b>Longitude:</b></td><td>".$lon."</td></tr><tr><td><b>Latitude:</b></td><td>" . $lat . "</td></tr></table>";
pg_close($db);

?>

</body>

</html>